home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MACD 5
/
MACD 5.bin
/
workbench
/
datatypes
/
playdt13.lha
/
PlayDT
/
PlayDT-src
/
UseAsl.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-06-05
|
4KB
|
179 lines
/****************************************************************
*
* $VER: UseAsl.c 1.3 (4.6.97) Tak Tang (tst92@ecs.soton.ac.uk)
*
* Copyright © 1997 Tak Tang
*
* You may use any part of this source code in your own programs
* provided that it is not called PlayDT.
*
*****************************************************************/
/**** Soft definitions ****/
#define ASM __asm __saveds
#define REG(x) register __ ## x
/**** Header files ****/
#include "PlayDT.h"
#include <libraries/asl.h>
#include <workbench/startup.h>
#include <datatypes/datatypesclass.h>
#include <clib/asl_protos.h>
#include <clib/dos_protos.h>
#include <clib/exec_protos.h>
#include <clib/datatypes_protos.h>
#include <pragmas/asl_pragmas.h>
#include <pragmas/dos_pragmas.h>
#include <pragmas/exec_pragmas.h>
#include <pragmas/datatypes_pragmas.h>
/**** Forward declarations ****/
ULONG ASM Filter (REG (a0) struct Hook *,
REG (a2) struct FileRequester *, REG (a1) struct AnchorPath *);
/****** UseASL *****************************************************
*
* NAME
* UseASL - use a file requester, and call PlayFile for files selected
*
* SYNOPSIS
* UseASL ( GlobalData )
*
* UseASL ( struct GlobalData * );
*
* FUNCTION
* UseASL will open an ASL file requester to prompt the user for
* sound files to play. The requester supports patterns,
* multiselect, and a datatypes filter, that ensures that only
* directories and sound files appear in the requester.
*
* UseAsl will keep opening the file requester until the user
* selects cancel, or there is a problem.
*
* INPUTS
* GlobalData -
*
* RESULT
*
* EXAMPLE
*
* NOTES
* All errors are reported via IntuiError
*
* BUGS
*
* SEE ALSO
* UseCli.c/UseCli(), UseWB.c/UseWB(), UseWB.c/IntuiError()
*
*****************************************************************************
*
*/
void UseASL(struct GlobalData *gd)
{
struct Library *AslBase;
struct FileRequester *fr;
struct Hook filter;
BPTR newlock;
BPTR oldlock;
struct WBArg *args;
ULONG i;
if (AslBase = OpenLibrary ("asl.library", 38L))
{
filter.h_Entry = (HOOKFUNC)Filter;
fr = AllocAslRequestTags ( ASL_FileRequest,
ASLFR_TitleText, "Select Sound to Play",
ASLFR_PositiveText, "Play",
ASLFR_DoMultiSelect, TRUE,
ASLFR_DoPatterns, TRUE,
ASLFR_FilterFunc, &filter,
ASLFR_RejectIcons, TRUE,
TAG_DONE );
if ( NULL != fr )
{
while ( (FALSE==gd->UserStop) && AslRequest(fr, NULL) )
{
if (fr->rf_NumArgs)
{
newlock = Lock (fr->rf_Dir, ACCESS_READ);
if ( NULL != newlock )
{
oldlock=CurrentDir(newlock);
args = fr->rf_ArgList;
for ( i=fr->rf_NumArgs; (i--) && (FALSE==gd->UserStop) ;args++ )
{
if ( PlayFile(gd, args->wa_Name) )
{
IntuiError( gd, args->wa_Name );
} /* if error */
} /* for each argument */
CurrentDir(oldlock);
UnLock(newlock);
} /* if Lock() OK */
else
{
IntuiError( gd, fr->rf_Dir );
} /* if Lock() FAIL */
} /* if NumArgs>0 */
} /* while ASLRequest() OK */
FreeAslRequest (fr);
} /* if NULL!=fr */
else
{
IntuiError( gd, "AllocAslRequest()" );
} /* if NULL==fr */
if (AslBase) CloseLibrary(AslBase);
} /* if OpenLibrary(Asl) OK */
else
{
IntuiError( gd, "OpenLibrary()" );
} /* if OpenLibrary(Asl) failed */
} /* UseASL() */
/**** Filter() ****/
ULONG ASM Filter (REG (a0) struct Hook *h, REG (a2) struct FileRequester *fr, REG (a1) struct AnchorPath *ap)
{
struct DataType *dtn;
ULONG use = FALSE;
BPTR flock, dlock, olock;
if ( dlock = Lock(fr->fr_Drawer, ACCESS_READ) ) {
olock=CurrentDir(dlock);
if ( flock = Lock(ap->ap_Info.fib_FileName, ACCESS_READ) )
{
if ( dtn = ObtainDataTypeA (DTST_FILE, (APTR) flock, NULL) )
{
if (dtn->dtn_Header->dth_GroupID == GID_SOUND) use = TRUE;
ReleaseDataType (dtn);
} /* if ObtainDataTypeA() OK */
UnLock (flock);
} /* if Lock(file) OK */
CurrentDir(olock);
UnLock(dlock);
} /* if Lock(Directory) OK */
return (use);
} /* Filter() */
/**** End of file ****/